﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GetAllUserACIs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            IAM.Interface.ModelExample.ACIManagement aci = new IAM.Interface.ModelExample.ACIManagement();
            IAM.Interface.Model.UserACIs acis = aci.GetAllUserACI();
            string strXml = acis.XML;

            strXml = "<ExportDate ExportTime=\"" + System.DateTime.Now.ToString() + "\" AppName=\"PreContract\" DataType=\"IDEN_USERLIST\" ><Result ErrorCode=\"0\" ErrorMessage=\"OK\" />" + strXml + "</ExportDate>";


            string filename = System.Configuration.ConfigurationManager.AppSettings["ExportFilePath"];

            if (System.IO.File.Exists(filename))
                System.IO.File.Delete(filename);

            this.txtRet.Text = strXml;

            string time = System.Configuration.ConfigurationManager.AppSettings["ExportTime"];
            DateTime starttime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd") + " " + time);

            PreContractWeb.ImpersonateHelper imp = new PreContractWeb.ImpersonateHelper();
            imp.impersonateValidUser(
                BEGDC.Utility.Security.EncryptTool.Decrypt(System.Configuration.ConfigurationManager.AppSettings["ShareFolderUser"], BEGDC.Utility.Configuration.ConfigConst.Key),
                BEGDC.Utility.Security.EncryptTool.Decrypt(System.Configuration.ConfigurationManager.AppSettings["ShareFolderDomain"], BEGDC.Utility.Configuration.ConfigConst.Key),
                BEGDC.Utility.Security.EncryptTool.Decrypt(System.Configuration.ConfigurationManager.AppSettings["ShareFolderPWD"], BEGDC.Utility.Configuration.ConfigConst.Key)
            );

            //if (System.DateTime.Now.AddSeconds(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ScheduleInterval"])) > starttime
            //        && System.DateTime.Now < starttime)
            //{
            System.IO.File.WriteAllText(filename, strXml, System.Text.Encoding.UTF8);
            //}

            imp.undoImpersonation();
        }
        catch (Exception ex)
        {
            this.txtErr.Text = ex.Message;
        }

    }
}
